import { createRouter, createWebHistory } from 'vue-router'
import HomeView from '../views/HomeView.vue'
import ProView from '../views/ProView.vue'
import LoginView from '../views/LoginView.vue'
import UserView from '../views/UserView.vue'
import Nouserview from '../views/Nouserview.vue'

const routes = [
  {
    path: "/",
    redirect: '/home'
  },
  {
    path: '/home',
    name: 'home',
    component: HomeView
  },
  {
    path: '/about',
    name: 'about',
    component: () => import(/* webpackChunkName: "about" */ '../views/AboutView.vue')
  },
  {
    path: "/pro/:name",
    name: "pro",
    component: ProView
  },
  {
    path: "/login",
    name: "login",
    component: LoginView,
    children: [
      {
        path: "user",
        component: UserView
      }, {
        path: "nouser",
        component: Nouserview
      }
    ]
  }
]

const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes
})

// Vue3 取消了  addRoutes([])  保留使用 addRoute({ path: '' , component: xxxx })
// 动态添加路由   动态路由 
router.addRoute({
  path: '/heihei',
  component: HomeView
})

router.beforeEach((to, from, next) => {
  console.log(to, from);
  next();
})

export default router
